﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="equsdsz.aspx.cs" Inherits="jnlamp.Web.mobile.equsdsz" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>杀虫灯系统平台</title>
    <link rel="stylesheet" type="text/css" href="easyui/themes/metro/easyui.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/mobile.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.mobile.js"></script>
    <script src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="../Script/datetime.js"></script>
    <script src="js/mobile.js"></script>
     <script src="../My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            initMenu();
        });
        function bindDDL() {
            var gprs_id = $.trim($("#txt_gprs_id").val());

            if (typeof (gprs_id) == "undefined" || gprs_id == "") {
                $.messager.alert("提示", "请输入网关号！", "info");
                return;
            }
            if (gprs_id != "" && gprs_id != null) {

                $('#cc').combobox({
                    url: "../api/hanlder.ashx?action=QueryDDl&gprs_id=" + gprs_id,
                    valueField: "scd_id",
                    textField: "scd_id",
                    panelHeight: "auto",
                    editable: false,
                    onSelect: function (record) {
                        $("#cc").val(record.name);
                    },
                    onLoadSuccess: function () { //加载完成后,设置选中第一项
                        var val = $(this).combobox("getData");
                        for (var item in val[0]) {
                            if (item == "scd_id") {
                                $(this).combobox("select", val[0][item]);
                            }
                        }
                    }
                });

            }
        }
        function ddclick(opt, id) {
            var gprs_id = $.trim($("#txt_gprs_id").val());

            if (typeof (gprs_id) == "undefined" || gprs_id == "") {
                $.messager.alert("提示", "请输入网关号！", "info");
                return;
            }

            var v = $('#cc').combobox('getValue');
            if (v == "") {
                alert("请选择灯号");
            }
            else {

                if (v.toString().length == 1) {
                    v = "00" + v;
                }
                else if (v.toString().length == 2) {
                    v = "0" + v;
                }

                $.ajax({
                    type: "post",
                    dataType: "text",
                    url: "../api/hanlder.ashx?action=AddScd&opt=" + (opt + v) + "&gprs_id=" + gprs_id + "&scd_id=" + v,
                    success: function aa(data) {
                        if (null != data && "[]" != data) {
                            if (data == "T") {
                                $.messager.alert("提示", "添加成功！", "info");
                                location.href = "listOp.aspx?gprs_id=" + gprs_id;
                            }

                        }

                    }
                });
            }

        }
        function selc() {
            var gprs_id = $.trim($("#txt_gprs_id").val());

            if (typeof (gprs_id) == "undefined" || gprs_id == "") {
                $.messager.alert("提示", "请输入网关号！", "info");
                return;
            }

            location.href = "listSj.aspx?gprs_id=" + gprs_id;
        }
        function submitTime() {
            var gprs_id = $.trim($("#txt_gprs_id").val());

            if (typeof (gprs_id) == "undefined" || gprs_id == "") {
                $.messager.alert("提示", "请输入网关号！", "info");
                return;
            }

            var ts = $("#txt_ts").val();
            if (parseInt(ts) >= 0 && parseInt(ts) <= 99) {
                var kdsj = $("#txt_kdsj").val();
                var xs = $("#txt_xs").val();
                var fz = $("#txt_fz").val();

               
                if ((xs == "" && fz == "") || (xs == "00" && fz == "00")) {
                    alert("开灯时长不能为0！");
                    return;
                }
                if (kdsj == "") {
                    kdsj = "00:00";
                }
                if (xs == "") {
                    xs = "00";
                }
                if (fz == "") {
                    fz = "00";
                }

                kdsj = kdsj.substring(0, 2) + kdsj.substring(3, 5);
                var kdsc = xs + fz;

                $.ajax({
                    type: "post",
                    dataType: "text",
                    url: "../api/hanlder.ashx?action=AddScdTime&kdsj=" + kdsj + "&gprs_id=" + gprs_id + "&kdsc=" + kdsc + "&ts=" + ts,
                    success: function aa(data) {
                        if (null != data && "[]" != data) {
                            if (data == "T") {
                                $.messager.alert("提示", "添加成功！", "info");
                                location.href = "listSj.aspx?gprs_id=" + gprs_id;
                            }
                        }

                    }
                });


            }
            else {
                alert("天数请输入99以内的正整数!");
            }

        }

    </script>
</head>
<body>
    <div class="easyui-navpanel" fit="true">
        <header>
            <div class="m-toolbar">
                <div class="m-title">单灯/时段设置</div>
            </div>
        </header>

        <ul class="m-list">
            <li>
                <input id="txt_gprs_id" class="easyui-textbox" style="width: 88%;" data-options=" label: '网关号:',labelPosition: 'top'" />
                <input type="button" value="查找" onclick="selc()" style="width: 12%" />
            </li>
            <li>
                开灯时间：<input id="txt_kdsj"   style="width: 60%;"  onfocus="WdatePicker({dateFmt:'HH:mm',readOnly:true})" />
            </li>
             <li>
                开灯时长：<input id="txt_xs"  style="width: 30%;" onfocus="WdatePicker({dateFmt:'HH',readOnly:true})" />小时
                 <input id="txt_fz"  style="width: 30%;"  onfocus="WdatePicker({dateFmt:'mm',readOnly:true})"/>分钟
            </li>
             <li>
                开灯天数：<input id="txt_ts"  style="width: 30%;"  /> <input type="button" value="提交" onclick="submitTime()" style="width: 20%" />
            </li>
            <li>
                单灯操作：<input id="cc" class="easyui-combobox"  name="dept" style="20%" />
                &nbsp;<input type="button" value="查找单灯" onclick="bindDDL()" style="width: 20%" />
            </li>
            <li>
                 <input type="button" value="单灯开启" onclick="ddclick('AOPEN', '09')" style="width: 30%" />
                 <input type="button" value="单灯关闭" onclick="ddclick('ACLOSE', '10')" style="width: 30%" />
            </li>
        </ul>



        <footer>
            <div class="m-buttongroup m-buttongroup-justified" style="width: 100%">
                <a id="mymain" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-chart',size:'large',iconAlign:'top',plain:true">查看设备</a>
                <a id="equqtop" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-clipart',size:'large',iconAlign:'top',plain:true">群体操作</a>
                <a href="/mobile/equsdsz.aspx" class="easyui-linkbutton" data-options="iconCls:'icon-large-shapes',size:'large',iconAlign:'top',plain:true">单灯/时段设置</a>
                <a id="myexist" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-smartart',size:'large',iconAlign:'top',plain:true">退出</a>
            </div>
        </footer>

    </div>

</body>
</html>
